package com.fire.mongo.lessons;

import java.io.IOException;

import com.fire.mongo.api.daos.TicketTest;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

/**
 * @date 2022/4/20
 * @author zwd
 * @email zwd@hhh.com
 */
public abstract class AbstractLesson extends TicketTest {
	protected MongoDatabase db;
	protected MongoDatabase testDb;
	protected MongoCollection<Document> moviesCollection;

	public AbstractLesson() {
		try {
			String mongoUri = getProperty("spring.mongodb.uri");
			String databaseName = getProperty("spring.mongodb.database");
			db = MongoClients.create(mongoUri).getDatabase(databaseName);
			moviesCollection = db.getCollection("movies");
			testDb = MongoClients.create(mongoUri).getDatabase("testDb");
		}
		catch (IOException e) {
			this.db = null;
		}
	}
}
